﻿@{
    Layout = null;
}
@if (ViewBag.Manager)
{
    <div id="SearchBrandAndProducts">
        <div id="SearchBrandAndProductsContent">
            <h5>Markadaki Ürünleri Listeleme</h5>
            @{Html.RenderAction("Brands", "Partials", new { full = 1 });}
            <hr />
            <h5>Ürün bulma ve düzenleme</h5>
            <input type="text" class="form-control" name="searchProductPanel" id="searchProductPanel" placeholder="Ürün adını yazınız">
            <div id="productsearch_search_resultsPanel" class="window productsearchviewPanel" style="display: none;">
                <div id="divProductSearchResultPanel" style="padding: 6px;">
                </div>
            </div>
            <hr />
            <h5>Kategori ve Marka Seçerek Listeleme</h5>
            @{Html.RenderAction("Categories2", "Partials", new { full = 1, id = "ManageSelectedCategory", GroupType = "A" });}
            <br />
            @{Html.RenderAction("Categories2", "Partials", new { full = 1, id = "ManageSelectedBrand", GroupType = "M" });}
            <div class="box-content">
                <div class="checkbox">
                    <label>
                        <input type="checkbox" id="tumu2">
                        Tüm Ürünler Gelsin (Pasif ve Varyantlar)
                    </label>
                </div>
                <div class="left">
                    <a href="/ProductManage/Edit?toEdit=AddNewProduct" class="btn btn-custom1 urunDuzenle fancybox.iframe" style="margin-bottom: 8px;">Yeni Ürün Ekle</a>
                </div>
                <div class="right">
                    <button type="button" name="ara2" class="btn btn-custom3" style="margin-bottom: 8px;" onclick="KategoriMarkaFiltrele();">Ara</button>
                </div>
            </div>
        </div>
        <div id="expandCollapseSearchBrandAndProducts"><i class="fa fa-edit fa-2x"></i></div>
    </div>
    <script>
        $('.editLiveSearch').live('click', function ()
        {
            $.fancybox.open({
                href: $(this).attr('href'),
                autoScale: true,
                width: 1000,
                height: 650,
                fitToView: true,
                autoSize: false,
                autoDimensions: true,
                autoScale: false,
                type: 'iframe',
                afterClose: function ()
                {
                }
            });
            return false;
        });
        function GetSearchProductPanel()
        {
            var myText = $("#searchProductPanel").val();
            $.ajax({
                url: '/Search/LiveSearchFull?search=' + myText,
                type: 'POST',
                success: function (result)
                {
                    $("#divLoadingGif").css("display", "none");
                    var myProductList = $(result);
                    var myHtlmString = '';
                    $.each(myProductList[0].LiveSearch, function (key, val)
                    {
                        myHtlmString += '<li><a href="/ProductManage/Edit/' + val.ProductId + '" data-id="' + val.ProductId + '" class="editLiveSearch">' + val.ProductId + ' - ' + val.Barcode + ' - ' + val.ProductName + '</a></li>';
                    });
                    myHtlmString = '<ul id="live_productsearch_resultsPanel">' + myHtlmString + '</ul><div class="clearfix"></div>';
                    $("#divProductSearchResultPanel").html(myHtlmString);

                    //$('.editLiveSearch').fancybox({
                    //    autoScale: true,
                    //    width: 1000,
                    //    height: 650,
                    //    fitToView: true,
                    //    autoSize: false,
                    //    autoDimensions: true,
                    //    autoScale: false,
                    //    afterClose: function ()
                    //    {
                    //    }
                    //});
                }
            });
        }
        var searchPanel = (function ()
        {
            var builderPanel = function ()
            {
                $(document).ready(function ()
                {
                    var object = $('#searchProductPanel', $('.window.productsearchviewPanel').hide().parent()).focus(function ()
                    {
                        this.active = true;
                        var value = $.trim(this.value);
                        if (value == object.data('empty'))
                        {
                            object.val('').parent().addClass('focus');
                        } else if (value.length >= 3) { searchPanel.show(); }
                    }).blur(function ()
                    {
                        this.active = false;

                        $(this.parentNode).removeClass('focus');
                        if ($.trim(object.val()) == '') { object.val(object.data('empty')); }
                    }).keyup(function ()
                    {
                        if (object.val().length >= 4)
                        {
                            $("#divLoadingGif").css("display", "block");
                            GetSearchProductPanel();
                            searchPanel.show();
                            $(this.parentNode).removeClass('focus');
                        } else
                        {
                            searchPanel.hide();
                            $(this.parentNode).addClass('focus');
                        }
                    });

                    var parent = object.parents('.container').hover(function () { this.active = true; }, function ()
                    {
                        this.active = false;
                        if (!object.prop('active')) { searchPanel.hide(); }
                    });
                });
            }
            builderPanel.prototype = {
                busy: false,
                show: function () { $('.window.productsearchviewPanel').stop(true, true).animate({ opacity: 'show', height: 'show' }, 'fast'); },
                hide: function () { $('.window.productsearchviewPanel').stop(true, true).animate({ opacity: 'hide', height: 'hide' }, 'fast'); }
            };

            return new builderPanel();
        })();
        var SearchBrandAndProductsExpanded = false;
        $('#expandCollapseSearchBrandAndProducts i').click(function ()
        {
            if (SearchBrandAndProductsExpanded)
            {
                $('#SearchBrandAndProducts').animate({ 'right': '-300px' });
                SearchBrandAndProductsExpanded = false;
            }
            else
            {
                $('#SearchBrandAndProducts').animate({ 'right': '0px' });
                SearchBrandAndProductsExpanded = true;
            }
        });
        function KategoriMarkaFiltrele()
        {
            var ktid = $('#ManageSelectedCategory').val();
            var mrid = $('#ManageSelectedBrand').val();
            if (ktid != "" && mrid != "")
            {

                if ($('#tumu2').is(':checked'))
                {
                    window.location = '/ProductsFull/Index/' + ktid + '/' + mrid;
                }
                else
                {
                    window.location = '/Products/Index/' + ktid + '/' + mrid;
                }
            }
        }
    </script>
}
